const fs = require('fs');
const path = require('path');

let s = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures/template.json')));

const recoMap = {};
s.recommendations.forEach((reco) => {
    // const { action, ad_product, classification } = reco 等同于const action = reco.action; const ad_product = reco.ad_product; const classification = reco.classification; 
    // ...others表示剩下的元素, 用others接收, 可以使用解构赋值的方式获取
    const { action, ad_product, classification, object, message, goals, scores, ...others } = reco;
    const { reco_type_id } = classification;
    console.log(others.xx);

    if (!recoMap[reco_type_id]) {
        recoMap[reco_type_id] = {};
    } else {
        throw new Error('aa');
    }
    message.fullMsgTemplate = message.full.slice();
    delete message['full'];

    recoMap[reco_type_id] = {
        action: action,
        ad_product,
        message,
        goal: goals.seller?.primary,
        level: object.type,
        score: scores.priority_seller,
        recoTypeName: classification.reco_type_name,
    };
});

console.log(JSON.stringify(recoMap, null, 2));
